﻿<template>
  <div class="deviceLog-container">
		<el-dialog v-model="isShowDialog" width="100%" height="100%" draggable="" :close-on-click-modal="false">
      <template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>{{ props.title }}</span>
				</div>
			</template>
    <el-card class="full-table" shadow="hover" style="margin-top: 5px">
     
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
                				row-key="id"
                @sort-change="sortChange"
				border="">
        <el-table-column type="index" label="序号" width="55" align="center"/>
        <el-table-column prop="createTime" label="创建时间"  show-overflow-tooltip="" />
        <el-table-column prop="receiveText" label="接收内容"  show-overflow-tooltip="" />
        <el-table-column prop="deviceProcotolProessResult" label="处理结果"  show-overflow-tooltip="" >
            <template #default="scope">
              <el-tag :type="dv('DeviceProcotolProessResult', scope.row.deviceProcotolProessResult)?.tagType"> {{dv('DeviceProcotolProessResult', scope.row.deviceProcotolProessResult)?.name}}</el-tag>
            </template>
          </el-table-column>
        <el-table-column prop="ip" label="Ip地址"  show-overflow-tooltip="" />
        <el-table-column prop="gateWayId" label="网关"  show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.gateWayIdGateWayName}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('deviceLog:update') || auth('deviceLog:delete')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditDeviceLog(scope.row)" v-auth="'deviceLog:update'"> 编辑 </el-button>
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delDeviceLog(scope.row)" v-auth="'deviceLog:delete'"> 删除 </el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				size="small"
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
      <printDialog
        ref="printDialogRef"
        :title="printDeviceLogTitle"
        @reloadTable="handleQuery" />
      <editDialog
        ref="editDialogRef"
        :title="editDeviceLogTitle"
        @reloadTable="handleQuery"
      />
    </el-card>
  </el-dialog>

  </div>
</template>

<script lang="ts" setup="" name="deviceLog">
  import { ref } from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
  import { auth } from '/@/utils/authFunction';
  import { formatDate } from '/@/utils/formatTime';
  import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
  import editDialog from '/@/views/Device/deviceLog/component/editDialog.vue'
  import { pageDeviceLog, deleteDeviceLog } from '/@/api/Device/deviceLog';
  import { getDeviceGateWayGateWayIdDropdown } from '/@/api/Device/deviceLog';
  import { getDeviceInfoDeviceIdDropdown } from '/@/api/Device/deviceLog';

//父级传递来的参数
var props = defineProps({
		title: {
		type: String,
		default: "",
	},
	});
  const showAdvanceQueryUI = ref(false);
  const printDialogRef = ref();
  const editDialogRef = ref();
  const loading = ref(false);
  const tableData = ref<any>([]);
  const queryParams = ref<any>({ });
  const tableParams = ref({
    page: 1,
    pageSize: 10,
    field: 'createTime', // 默认的排序字段
    order: 'descending', // 排序方向
    descstr: 'descending', // 降序排序的关键字符
    total: 0 as any,
  });
	const isShowDialog = ref(false);
  const printDeviceLogTitle = ref("");
  const editDeviceLogTitle = ref("");

  // 改变高级查询的控件显示状态
  const changeAdvanceQueryUI = () => {
    showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
  }

  // 查询操作
  const handleQuery = async () => {
    loading.value = true;
    var res = await pageDeviceLog(Object.assign(queryParams.value, tableParams.value));
    tableData.value = res.data.result?.items ?? [];
    tableParams.value.total = res.data.result?.total;
    loading.value = false;
  };

  // 列排序
  const sortChange = async (column: any) => {
	tableParams.value.field = column.prop;
	tableParams.value.order = column.order;
	await handleQuery();
  };
// 打开弹窗
const openDialog = async (row: string) => {
		// ruleForm.value = JSON.parse(JSON.stringify(row));
		// 改用detail获取最新数据来编辑
		queryParams.value.deviceId=row;
		isShowDialog.value = true;
    handleQuery();
	};

  

  // 删除
  const delDeviceLog = (row: any) => {
    ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
  .then(async () => {
    await deleteDeviceLog(row);
    handleQuery();
    ElMessage.success("删除成功");
  })
  .catch(() => {});
  };

  // 改变页面容量
  const handleSizeChange = (val: number) => {
    tableParams.value.pageSize = val;
    handleQuery();
  };

  // 改变页码序号
  const handleCurrentChange = (val: number) => {
    tableParams.value.page = val;
    handleQuery();
  };

  const deviceGateWayGateWayIdDropdownList = ref<any>([]); 
  const getDeviceGateWayGateWayIdDropdownList = async () => {
    let list = await getDeviceGateWayGateWayIdDropdown();
    deviceGateWayGateWayIdDropdownList.value = list.data.result ?? [];
  };
  getDeviceGateWayGateWayIdDropdownList();
  
  const deviceInfoDeviceIdDropdownList = ref<any>([]); 
  const getDeviceInfoDeviceIdDropdownList = async () => {
    let list = await getDeviceInfoDeviceIdDropdown();
    deviceInfoDeviceIdDropdownList.value = list.data.result ?? [];
  };
  getDeviceInfoDeviceIdDropdownList();
  
  handleQuery();
  defineExpose({ openDialog });

</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>

